package com.yznote.cloudesk.logs.service.impl;

import com.yznote.cloudesk.common.pojo.YLogs;
import com.yznote.cloudesk.logs.mapper.YLogsMapper;
import com.yznote.cloudesk.logs.service.LogService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    YLogsMapper logsMapper;
    @Override
    public List<YLogs> queryLogs(Integer pageSize,Integer pageNum) {
        return logsMapper.getLogs((pageNum-1)*pageSize,pageSize);
    }

    @Override
    public Integer getNumInSec(LocalDateTime localDateTime) {
        return logsMapper.getCountBetween(localDateTime,localDateTime.plusSeconds(1));
    }

    @Override
    public List<Integer> getNumByDay() {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime start = LocalDateTime.of(now.getYear(),now.getMonth(),now.getDayOfMonth(),0,0,0,0);
        List<Integer> res = new ArrayList<>();
        for(int i=0;i<24;i++){
            res.add(logsMapper.getCountBetween(start,start.plusHours(1)));
            start = start.plusHours(1);
        }
        return res;
    }

    @Override
    public Integer getCount() {
        return logsMapper.getCount();
    }
}
